#ifndef __STREAMINGBUFFER_OPENAL_H__
#define __STREAMINGBUFFER_OPENAL_H__

#pragma once
#include "isoundbuffer.h"
#include "al/al.h"

#include <vorbis/vorbisfile.h>

namespace openAL {

#define OGG_STREAMINGBUFFER_SIZE     32768       // 32 KB buffers

class DLL_EXPORT StreamingBuffer_OpenAL :
	public audio::ISoundBuffer
{
public:
	StreamingBuffer_OpenAL(const std::string &fileName);
	virtual ~StreamingBuffer_OpenAL(void);

	/**
	*	Fills the passed Buffer with the next sample data.
	*	\param ALuint _uiBufferID Id of the openAl-buffer.
	*	\param int _iBufferSize Size of the buffer in bytes.
	*	Returns 'false' if soundfile reched its end.	
	*/
	bool fillBuffer(ALuint _uiBufferID);

	/**
	*	Fills the passed Buffer with silence.
	*	\param ALuint _uiBufferID Id of the openAl-buffer.
	*	\param int _iSilence Length of the buffer in ms
	*/
	void fillBufferWithSilence(ALuint _uiBufferID, int _iSilence);

	/**
	*	Opens the file and make the buffer ready for streaming data.
	*/
	bool open();

	/**
	*	Closes the file. Buffer can only be used again by re-opening.
	*/
	bool close();

protected:
	
	std::string m_sFileName;	///< Name of the soundFile.
	bool m_bFileOpen;			///< State of the soundFile. Open?
	OggVorbis_File oggFile;		///< The soundFile
	vorbis_info *m_pInfo;		///< A pointer to some informations about the ogg file
};

}

#endif //__STREAMINGBUFFER_OPENAL_H__